using System;
using System.Collections.Generic;
using System.Text;
using WebCrawlerTools.search;
using WebCrawlerTools;

namespace TemplateCreateTools
{
    public class SourceItem
    {
        private string fileName;
        private string source;

        public SourceItem(string fileName)
        {
            this.fileName = fileName;
            init();
        }

        public SourceItem()
        {
            
        }
    
        public string FileName
        {
            get
            {
                return fileName;
            }
            set
            {
                fileName = value;
            }
        }

        public string Source
        {
            get
            {
                return source;
            }
            set
            {
                source = value;
            }
        }

        private void init()
        {
            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(fileName, Encoding.Default))
                {
                    source = reader.ReadToEnd();
                    reader.Close();
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.StackTrace);
            }
        }

        public bool Judge(string template)
        {
            PageEngine pe = new PageEngine();
            pe.Source = source;
            pe.Template = new STemplate(template);
            pe.analysis();
            return pe.Result.Data.Count >0;
        }
    }
}
